//
//  DefaultAnimationController.m
//  CoreAnimationDemo
//
//  Created by AY on 17/5/31.
//  Copyright © 2017年 Alex. All rights reserved.
//

#import "DefaultAnimationController.h"

@interface DefaultAnimationController ()
@property (nonatomic, strong) CALayer *layer;
@end

@implementation DefaultAnimationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // 隐式动画只能作用在非根层, 所以需要创建子层
    CALayer *layer = [CALayer layer];
    layer.backgroundColor = [UIColor redColor].CGColor;
    layer.bounds = CGRectMake(0, 0, 100, 100);
    layer.position = CGPointZero;
    layer.anchorPoint = CGPointMake(0, 0);
    self.layer = layer;
    [self.view.layer addSublayer:layer];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [CATransaction begin]; // 开启事务
    [CATransaction setDisableActions:NO]; // 关闭隐式动画 (默认开启)
    self.layer.position = CGPointMake(100, 100);
    [CATransaction commit];
}
@end
